//
//  JYTBaseViewController.m
//  JYT_IOS
//
//  Created by wolf －yuan on 16/11/13.
//  Copyright © 2016年 com.yuan. All rights reserved.
//

#import "JYTBaseViewController.h"

@interface JYTBaseViewController () <ProtocolBaseHeadEvent>
{
    JYTBaseHeadView *bHeadView;
}
@end

@implementation JYTBaseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self.view setBackgroundColor:[UIColor colorWithRed:0xef/255.0f green:0xef/255.0f blue:0xf4/255.0f alpha:1]];
    
    JYTBaseHeadView *headView = [[JYTBaseHeadView alloc] init];
    headView.delegate = self;
    [self.view addSubview:headView];
    bHeadView = headView;
    [bHeadView setHidden:YES];
    CGFloat navBarTobottom = CURRENT_SCREEN_HEIGHT - NAVIGATION_BAR_HEIGHT - STATUS_BAR_HEIGHT;
    
    UIEdgeInsets padding = UIEdgeInsetsMake(0, 0, navBarTobottom, 0);
    
    [headView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.view).with.insets(padding);
    }];
    
    [headView setIsNormalBar];
}


- (void) setNavgationBarWithDic:(NSDictionary *)dic
{
    [bHeadView setHidden:NO];
    [bHeadView setNavgationBarWithDic:dic];
    
}


- (void) goBack
{
    [self.containerDelegate popViewControllerFromContainer];
}


- (void) pushViewController:(JYTBaseViewController *)bvc
{
    [self.containerDelegate pushViewControllerToContainer:bvc];
}


- (void)baseGoToNextViewController
{
    MyLog(@"未实现");

}


- (void)clickLeftBtn
{
    [self goBack];
}


- (void)clickRightBtn
{
    [self baseGoToNextViewController];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


- (void) goToRootViewController
{
    [self.containerDelegate PopToRootViewController];
}

- (void)goToExactViewController:(JYTBaseViewController *)bvc
{
    if (self.containerDelegate && [_containerDelegate respondsToSelector:@selector(PopToExactViewController:)]) {
        [self.containerDelegate PopToExactViewController:bvc];
        
    }
}

//- (void) goToExactViewController:(JYTBaseViewController *)bvc
//{
//    [self.containerDelegate PopToExactViewController:bvc];
//}

- (void) goToViewControllerIndexOfContainer:(NSInteger) index
{
    NSArray *arr = self.navigationController.viewControllers;
    
    NSInteger count = arr.count;
    
    NSLog(@"当前下标:%ld", count - 1);
    
    JYTBaseViewController *bvc;
    
    if (index < count && index > 1) {
        bvc = arr[index - 1];
        [self goToExactViewController:bvc];
        
    } else {
        [self goToRootViewController];
    }
    
}

- (void)gotoViewController:(NSString *)viewControllerName
{
    if (!viewControllerName) {
        return;
    }
    
    JYTBaseViewController *bvc = nil;
    
    NSString *name = viewControllerName;
    Class vcc = NSClassFromString(name);
    
    NSArray *arr = self.navigationController.viewControllers;
    
    for (UIViewController *vc in arr) {
        
        if (vcc && [vc isKindOfClass:vcc]) {
            bvc = (JYTBaseViewController *)vc;
            break;
        }
    }
    
    [self goToExactViewController:bvc];
}

@end
